<?php
class UpLoadImageAction extends dpAction
{
	public function run()
	{
		D::import('admin:model.*');
		$site_id   = empty($_SESSION['admin_site_id']) ? 1 : (int)$_SESSION['admin_site_id'];
		$site_info = siteModel::model()->getSiteInfo($site_id);
		$type      = 'jpg,gif,png,bmp,jpeg';
		$dir = null;
		if ($site_info['file_save_dir'] == 1) {
			$dir = date('Y');
		} else if ($site_info['file_save_dir'] == 2) {
			$dir = null;
		} else {
			$dir = date('Ymd');
		}

		$upload = new dpUpload(
			array(
				'size'  => $site_info['site_upload_size'],
				'type'  => $type,
				'child' => $dir
			)
		);
		$info = $upload->save('upfile');

		if (!empty($info) && empty($info['error'])) $info['error'] = 'SUCCESS';

		$array = array(
			'url'   => empty($info['new_name']) ? '' : substr($info['new_name'], 1),
			'title' => '',
			'original' => empty($info['name']) ? '' : $info['name'],
			'state' => $info['error']
 		);

		$this->ajaxReturn($array);
	}
}